# encoding: utf-8
""" 
@version: v1.0 
@author: autumner 
@license: Apache Licence  
@contact: 18322313385@163.com 
@site:  https://gitee.com/autumner/pythoncookbook
@software: PyCharm 
@file: shell_modi_file_time.py 
@time: 2019/8/2 上午10:29
@note:
查看在一段时间内修正的文件
"""
from os import walk
from os.path import exists, normpath, join, getmtime
from time import time, strftime, localtime
from sys import argv, stderr

def modified_within(top, seconds):

    now = time()

    for path, dirs, files in walk(top):
        for name in files:
            fullpath = join(path, name)
            if exists(fullpath):
                mtime = getmtime(fullpath)
                if mtime > (now - seconds):
                    print(fullpath, strftime('%Y-%m-%d %H:%M:%S', localtime(mtime)))


if __name__ == '__main__':

    if len(argv) != 3:
        print('Usage: {} dir seconds'.format(argv[0]), file=stderr)
        raise SystemExit(1)

    try:

        modified_within(argv[1], float(argv[2]))
    except:
        print()
        raise SystemExit(1)
    # modified_within('/home/autumner', 3600)